import { syncSetTimeout, sendMessage, getMessage, dispatch } from "../../global/tools.js";

export default class Permission {
    static count = 0;
    constructor() {
        Permission.count++;
        if (Permission.count >= 2) {
            alert("collectionPlugin: \nError: Permission.count >= 2，即将刷新页面。");
            location.reload(true);
        } 
        this.init();
    } 
    init() {
    }
    async getUserPermission(userName) {
        return new Promise((resolve, reject) => {
            getMessage("aiccyun_permission", (message) => {
                switch (message.title) {
                    case "getUserPermission":
                        resolve(message.data.available || false);
                        break;
                    default:
                        break;
                }
            });
            sendMessage({
                from: "aiccyun_permission",
                to: "background",
                toUrl: "background",
                title: "getUserPermission",
                data: userName
            });
        });
    }
}